home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-12-01 | 5.4 KB | 189 lines | [TEXT/PJMM] |
- {------------------------------------------------}
- { MeterWindow Unit. }
- { This unit contains all the functions and }
- { procedures needed to support the initializing, }
- { displaying, updating, and destroying of the }
- { Meter Window. }
-
- unit MeterWindow;
-
- interface
-
- procedure mWindowInit;
-
- procedure mWindowDraw;
-
- procedure mWindowTitle (mStr: Str255);
-
- procedure mWindowUpdate (curI, maxI: longint);
-
- procedure mWindowKill;
-
- implementation
-
- { Constants to control the size and placement of the Meter Window title and meter box.}
- const
- mRx = 13;
- mRy = 24;
- mRw = 250;
- mRh = 16;
-
- tRx = 13;
- tRy = 1;
- tRw = 253;
- tRh = 16;
-
- var
- mWPtr: WindowPtr;
-
- {--------------------------------------------------------------------------------------------}
- { mWindowInit procedure }
- { This procedure initializes the meter window and draw it in the middle of the screen. }
-
- procedure mWindowInit;
-
- { The constants for the height and width of the Meter Window.}
- const
- mWwidth = 280;
- mWheight = 60;
-
- var
- savePort: GrafPtr;
- iRect: Rect;
- mwXOffset, mwYOffset: integer;
-
- begin
- SetRect(iRect, 0, 0, mWwidth, mWheight);
- { Create the Meter Window with a window definition ID equal to 1.}
- mWPtr := NewWindow(nil, iRect, '', false, 1, Pointer(-1), false, longint(0));
- iRect := screenBits.bounds;
- { Figure out the x and y offsets in pixels to put the Meter Window in the center of this }
- { screen. After that move the window there and display the empty window.}
- mwXOffset := integer(round(((iRect.right - iRect.left) - (mWptr^.portRect.right - mWptr^.portRect.left)) / 2));
- mwYOffset := integer(round(((iRect.bottom - iRect.top) - (mWptr^.portRect.bottom - mWptr^.portRect.top)) / 2));
- MoveWindow(mWPtr, mwXOffset, mwYOffset, false);
- ShowWindow(mWPtr);
- end;
-
- {--------------------------------------------------------------------------------------------}
- { mWindowDraw procedure }
- { This procedure draws the meter box with its graduations and the corresponding annotation. }
-
- procedure mWindowDraw;
-
- { These constatns control the placement of the 5% and 10% graduations in the meter box based}
- { on a meter box that is 250 pixels wide.}
- const
- fiveSize = 1;
- fiveStep = 12;
- tenSize = 3;
- tenStep = 25;
-
- var
- i: integer;
- mRect: Rect;
- savePort: GrafPtr;
-
- begin
- GetPort(savePort);
- SetPort(mWPtr);
- { Erase the Meter Window in case something is already drawn there.}
- EraseRect(mWPtr^.portRect);
- { Set up the meter box in the mRect rectangle.}
- SetRect(mRect, mRx, mRy, mRx + mRw, mRy + mRh);
- TextFont(0);
- TextSize(12);
- PenSize(1, 1);
- { Draw the frame around the meter box rectangle.}
- InsetRect(mRect, -1, -1);
- FrameRect(mRect);
- InsetRect(mRect, 1, 1);
- { Draw the first 5% graduation then let the following loop do the rest.}
- MoveTo(mRect.left + fiveStep, mRect.top - 1);
- Line(0, fiveSize);
- MoveTo(mRect.left + fiveStep, mRect.bottom);
- Line(0, -fiveSize);
- for i := 1 to 9 do
- begin
- MoveTo(mRect.left + (i * tenStep) - 1, mRect.top - 1);
- Line(0, tenSize);
- MoveTo(mRect.left + (i * tenStep) - 1, mRect.bottom);
- Line(0, -tenSize);
- MoveTo(mRect.left + (i * tenStep) + fiveStep, mRect.top - 1);
- Line(0, fiveSize);
- MoveTo(mRect.left + (i * tenStep) + fiveStep, mRect.bottom);
- Line(0, -fiveSize);
- end;
- { Now draw the appropriate meter box annotation.}
- MoveTo(mRect.left + 65, mRect.bottom + mRh);
- DrawString('Percent Complete');
- MoveTo(mRect.left - 5, mRect.bottom + mRh);
- DrawString('0%');
- MoveTo(mRect.right - 20, mRect.bottom + mRh);
- DrawString('100%');
- SetPort(savePort);
- end;
-
- {--------------------------------------------------------------------------------------------}
- { mWindowTitle procedure }
- { This procedure draws the title of the meter window in the tRect rectangle.}
-
- procedure mWindowTitle;
-
- var
- savePort: GrafPtr;
- tRect: Rect;
-
- begin
- GetPort(savePort);
- SetPort(mWPtr);
- { Set up the title rectangle in the tRect structure, erase the rectangle, then draw the}
- { title string in the rectangle.}
- SetRect(tRect, tRx, tRy, tRx + tRw, tRy + tRh);
- EraseRect(tRect);
- MoveTo(tRect.left, tRect.bottom);
- DrawString(mStr);
- SetPort(savePort);
- end;
-
- {--------------------------------------------------------------------------------------------}
- { mWindowUpdate procedure }
- { This procedure fills in the meter box based on the curI and maxI parameters. CurI is the}
- { current step in the process with maxI steps.}
-
- procedure mWindowUpdate;
-
- var
- pDone: integer;
- mRect: Rect;
- savePort: GrafPtr;
-
- begin
- GetPort(savePort);
- SetPort(mWPtr);
- { Determine which percent of the process is done and load it in pDone.}
- if maxI = 0 then
- pDone := 0
- else
- pDone := integer(round(curI / maxI * 100));
- { Just in case the percent done is greater than 100%.}
- if pDone > 100 then
- pDone := 100;
- SetRect(mRect, mRx, mRy, mRx + mRw, mRy + mRh);
- { Since the meter box is 250 pixels wide, each percent corresponds to 2.5 pixels.}
- mRect.right := mRect.left + integer(round((pDone * 2.5)));
- FillRect(mRect, black);
- SetPort(savePort);
- end;
-
- {--------------------------------------------------------------------------------------------}
- { mWindowKill procedure }
- { This procedure disposes of the Meter Window data structure.}
-
- procedure mWindowKill;
-
- begin
- DisposeWindow(mWPtr);
- end;
-
- end.